home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 004 / kermit / main.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  2KB  |  134 lines

  1. /*    @(#)main.c    1.1    1/26/85    */
  2.  
  3. #include "kermit.h"
  4. #include "errors.h"
  5.  
  6. static int rflg = 0;
  7. static int Rflg = 0;
  8. static int sflg = 0;
  9.  
  10. static VOID OpenRemote ();
  11. static VOID Options ();
  12. static VOID CleanUp ();
  13.  
  14.  
  15. /*
  16.  *      K e r m i t
  17.  *
  18.  *      Main routine - parse command and option, set up the
  19.  *      tty lines and dispatch to the appropriate routine.
  20.  */
  21.  
  22. main (argc, argv)
  23. int argc;
  24. char *argv[];
  25. {
  26.     DBUG_ENTER ("main");
  27.     DBUG_PROCESS (argv[0]);
  28.     Options (argc, argv);
  29.     OpenRemote ();
  30.     SetSpeed ();
  31.     GetModes ();
  32.     SetUp ();
  33.     if (cflg) {
  34.     Connect ();
  35.     } else if (sflg) {
  36.     Send (argv);
  37.     } else if (rflg) {
  38.     Receive ();
  39.     }
  40.     CleanUp ();
  41.     DBUG_RETURN (0);
  42. }
  43.  
  44.  
  45. /*
  46.  *    Note that if we are a remote kermit then file with
  47.  *    descriptor 0 is used to read/write packets.
  48.  */
  49.  
  50. static VOID OpenRemote ()
  51. {
  52.     DBUG_ENTER ("OpenRemote");
  53.     if (!Rflg) {
  54.     host = TRUE;
  55.     DBUG_2 ("host", "we are a host kermit");
  56.     } else {
  57.     remtty = TERMINAL;
  58.     host = FALSE;
  59.     DBUG_2 ("host", "we are a remote kermit");
  60.     }
  61.     DBUG_3 ("tty", "open '%s' as communications port", remtty);
  62.     remfd = open (remtty, 2, 0777);
  63.     if (remfd < 0) {
  64.     Error (REMTTY, remtty);
  65.     WrapUp (1);
  66.     }
  67.     DBUG_VOID_RETURN;
  68. }
  69.  
  70.  
  71. static VOID Options (argc, argv)
  72. int argc;
  73. char *argv[];
  74. {
  75.     register int fchar;
  76.     extern char *optarg;
  77.     extern int getopt ();
  78.  
  79.     DBUG_ENTER ("options");
  80.     if (argc < 2) {
  81.     Usage ();
  82.     }
  83.     while ((fchar = getopt (argc, argv, "#:hcstrRme:l:b:p:")) != EOF) {
  84.     switch (fchar) {
  85.         case '#': 
  86.         DBUG_PUSH (optarg);
  87.         break;
  88.         case 'h': 
  89.         Help ();
  90.         exit (0);
  91.         case 'c': 
  92.         cflg++;
  93.         break;
  94.         case 'm':
  95.             mflg++;
  96.         break;
  97.         case 's': 
  98.         sflg++;
  99.         break;
  100.         case 't':
  101.             tflg++;
  102.         break;
  103.         case 'r': 
  104.         rflg++;
  105.         break;
  106.         case 'R':
  107.             Rflg++;
  108.         break;
  109.         case 'e': 
  110.         escchr = atoi (optarg);
  111.         DBUG_3 ("args", "esc char is %o", escchr);
  112.         break;
  113.         case 'l': 
  114.         remtty = optarg;
  115.         DBUG_3 ("args", "remote tty line is %s", remtty);
  116.         break;
  117.         case 'p': 
  118.         photo = optarg;
  119.         DBUG_3 ("args", "photo file is %s", photo);
  120.         break;
  121.         case 'b': 
  122.         NewSpeed (atoi (optarg));
  123.         DBUG_3 ("args", "speed is %d baud", optarg);
  124.         break;
  125.     }
  126.     }
  127.     if ((cflg + sflg + rflg) != 1) {
  128.     Error (MODE);
  129.     WrapUp (1);
  130.     }
  131.     DBUG_VOID_RETURN;
  132. }
  133.  
  134.